﻿//using System.Collections;
//using System.Collections.Generic;
//using UnityEngine;
//using UnityEditor;

//namespace Utility.Inspector
//{
//	public static class ObjectList
//	{
//		public struct Data
//		{
//			public Vector2 scrollPos;
//			public int selectedIndex;
//			public bool showContent;
//		}

//		public struct Options
//		{
//			public bool? showIndex;
//			public bool ShowIndex => showIndex ?? false;

//			public int? itemsPerScrollPage;
//			public int ItemsPerScrollPage => itemsPerScrollPage ?? 10;

//			public System.Action<ScriptableObject> onAddItem;
//		}

//		static GUIContent iconToolbarPlus = EditorGUIUtility.IconContent ("Toolbar Plus", "Add to list");
//		static GUIContent iconToolbarPlusMore = EditorGUIUtility.IconContent ("Toolbar Plus More", "Choose to add to list");
//		static GUIContent iconToolbarMinus = EditorGUIUtility.IconContent ("Toolbar Minus", "Remove selection from list");
//		static GUIContent iconPagePrev = EditorGUIUtility.IconContent ("Animation.PrevKey", "Previous page");
//		static GUIContent iconPageNext = EditorGUIUtility.IconContent ("Animation.NextKey", "Next page");

//		static GUIStyle style_content = new GUIStyle ()
//		{
//			margin = new RectOffset (2, 2, 0, 0)
//		};

//		static GUIStyle style_left = new GUIStyle ()
//		{
//			padding = new RectOffset (3, 3, 3, 1)
//		};

//		static GUIStyle style_label = new GUIStyle ("Hi Label")
//		{
//			margin = new RectOffset (),
//			padding = new RectOffset (3, 3, 0, 0),
//			stretchWidth = true

//		};

//		public static Data Layout<T> (Data data, GUIContent title, IList<T> list, Options options = default, params GUILayoutOption[] layoutOptions)
//			where T : ScriptableObject
//		{
//			float width_left = 200;
//			float height = options.ItemsPerScrollPage * EditorGUIUtility.singleLineHeight + 35;

//			using (VerticalScope.New (layoutOptions))
//			{
//				//header
//				Rect rect_title = GUILayoutUtility.GetRect (100, EditorGUIUtility.singleLineHeight);
//				GUI.Box (rect_title, "", GUI.skin.button);
//				rect_title.x += 15;
//				data.showContent = EditorGUI.Foldout (rect_title, data.showContent, title, true);
//				if (!data.showContent)
//				{
//					return data;
//				}
//				//content scope
//				using (var scope_main = HorizontalScope.New (style_content))
//				{
//					Rect rect_left = new Rect (scope_main.Rect) { width = width_left };
//					Rect rect_right = new Rect (rect_left) { x = rect_left.x + rect_left.width, width = scope_main.Rect.width - rect_left.width };
//					GUI.Box (rect_left, "");
//					GUI.Box (rect_right, "");

//					ScriptableObject selectedObject = null;

//					//left region
//					using (var scope = VerticalScope.New (style_left, GUILayout.Width (width_left)))
//					{
//						//list
//						using (ScrollViewScope.New (ref data.scrollPos))
//						{
//							for (int i = 0; i < list.Count; i++)
//							{
//								using (var scope_item = HorizontalScope.New ())
//								{
//									bool selected = data.selectedIndex == i;
//									ScriptableObject obj = list[i];

//									if (selected)
//									{
//										selectedObject = obj;
//									}

//									//index
//									string index = options.ShowIndex ? i.ToString () + ": " : "";
//									//label
//									string label = index + (obj ? obj.name : "Null");
//									if (GUILayout.Toggle (selected, label, style_label) && Event.current.button == 0)
//									{
//										data.selectedIndex = i;
//									}
//								}
//							}
//						}

//						//toolbar
//						using (var scope_toolbar = HorizontalScope.New (FlexibleTypes.Begin))
//						{
//							GUI.Box (scope_toolbar.Rect, "", EditorStyles.toolbar);
//							//add
//							if (GUILayout.Button (iconToolbarPlus, EditorStyles.toolbarButton, GUILayout.Width (30)))
//							{
//								var inst = ScriptableObject.CreateInstance<T> ();
//								list.Add (inst);
//								options.onAddItem?.Invoke (inst);
//							}
//							//add plus
//							if (GUILayout.Button (iconToolbarPlusMore, EditorStyles.toolbarButton, GUILayout.Width (30)))
//							{

//							}
//						}
//					}

//					//right region
//					using (var scope = VerticalScope.New ())
//					{
//						if (selectedObject == null)
//						{

//						}
//						else
//						{
//							var editor = Editor.CreateEditor (selectedObject);
//							editor.OnInspectorGUI ();
//						}
//					}
//				}
//			}
//			return data;
//		}




//	}
//}